package xiao.trip.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import xiao.trip.Do.helpDO2;
import xiao.trip.dao.UserDAOByXML2;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("a")
public class helpController2 {
   @Autowired
    UserDAOByXML2 userDAOByXML2;
    @RequestMapping("/toaddhelp")
    public String toaddhelp(){
        return "moneyhelp/addhelp";
    }
    @RequestMapping("/helpindex")
    public String getUserList( Model model){
        List<helpDO2> moneyhelplist = userDAOByXML2.selectAllmoneyhelp();
        model.addAttribute("moneyhelplist",moneyhelplist);
        return "moneyhelp/helpindex";
    }

    @RequestMapping("/addmoneyhelp")
    public String addhelp(HttpServletRequest Request, Map map){
        String moneyhelp =Request.getParameter("moneyhelp");
        String money =Request.getParameter("money");
        String starttime =Request.getParameter("starttime");
        String endtime =Request.getParameter("endtime");
        String telephone =Request.getParameter("telephone");
        if (userDAOByXML2.insertmonethelp(moneyhelp,money,starttime,endtime,telephone)!=null){
            map.put("insertright",("插入成功"));
            return "forward:helpindex";
        }
        else{
            map.put("inserterror",("插入失败"));
            return("forward:helpindex");
    }
   }
}
